package com.cndongtai.dao.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Repository;

import com.cndongtai.dao.BaseDao;
import com.cndongtai.dao.inter.RoleMapper;
import com.cndongtai.po.Role;

@Repository("roleDao")
public class RoleDao extends BaseDao implements RoleMapper {

	@Override
	public List<Role> queryRoleList() {
		SqlSession sqlSession = getSqlSession();
		
		try {
			RoleMapper operation = sqlSession.getMapper(RoleMapper.class);
			return operation.queryRoleList();
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return null;
	}

	@Override
	public boolean addRole(Role role) {
		SqlSession sqlSession = getSqlSession();
		
		try {
			RoleMapper operation = sqlSession.getMapper(RoleMapper.class);
			return operation.addRole(role);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return false;
	}

	@Override
	public Role queryRoleById(Long roleId) {
		SqlSession sqlSession = getSqlSession();
		
		try {
			RoleMapper operation = sqlSession.getMapper(RoleMapper.class);
			return operation.queryRoleById(roleId);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return null;
	}

	@Override
	public boolean updateRole(Role role) {
		SqlSession sqlSession = getSqlSession();
		
		try {
			RoleMapper operation = sqlSession.getMapper(RoleMapper.class);
			return operation.updateRole(role);
		}catch(Exception e) {
			e.printStackTrace();
		}finally {
			sqlSession.close();
		}
		
		return false;
	}

}
